package Q396

import java.util.*
import kotlin.math.max

class Main {

}

fun main(){

}

// 旋转函数
class Solution {
    fun maxRotateFunction(nums: IntArray): Int {
        var f = 0
        val n = nums.size
        val numSum = Arrays.stream(nums).sum()
        for (i in 0 until n) {
            f += i * nums[i]
        }
        var res = f
        for (i in n - 1 downTo 1) {
            f += numSum - n * nums[i]
            res = max(res, f)
        }
        return res
    }
}
